package waitNotify;

public class Foodie extends Thread{
    @Override
    public void run() {
        while (true){
            synchronized (Desk.lock){
                //先判断吃够了没有
                if(Desk.count == 0){
                    break;
                }else {
                    //看看桌子上有没有面条
                    if(Desk.foodFlag == 1){
                        //有就吃一碗
                        Desk.count --;
                        System.out.println("吃一碗面,满福,还剩" + Desk.count + "碗");
                        //吃完了桌子空了叫醒厨师
                        Desk.foodFlag = 0;
                        Desk.lock.notifyAll();
                    }else {
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }
}
